const STATUS_TITLE = 1;
const STATUS_GAME = 2;

function Quadranoid ()
{
	console.debug ( "Quadra INIT" );

	this.status = STATUS_TITLE;
}

Quadranoid.prototype.init = function ()
{
	var self = this;

	function _wait ( cback )
	{
		if ( CGE.ready () ) 
			cback ();
		else
			setTimeout ( function () { _wait ( cback ); }, 500 );
	}

	CGE.canvas_handler.add ( "screen", 400, 400 );

	this._title_resources ();

	_wait ( function () { self.app_start (); } );
};

Quadranoid.prototype.app_start = function ()
{
	var self = this;

	console.debug ( "APP START" );

	var c = CGE.canvas_handler.get ( "screen" );
	
	c.render ( "dest_canvas" );

	this._prepare_title ();


	CGE.keys.add ( CGE.KEY_CURSOR_LEFT, function ( evt ) { _x_delta = -3; }, function ( evt ) { _x_delta = 0; } );
	CGE.keys.add ( CGE.KEY_CURSOR_RIGHT, function ( evt ) { _x_delta = 3; }, function ( evt ) { _x_delta = 0; } );
	CGE.keys.add ( CGE.KEY_CURSOR_UP, function ( evt ) { _y_delta = -3; }, function ( evt ) { _y_delta = 0; } );
	CGE.keys.add ( CGE.KEY_CURSOR_DOWN, function ( evt ) { _y_delta = 3; }, function ( evt ) { _y_delta = 0; } );
	CGE.keys.listen ( true );

	CGE.render ( function () { self.render (); }, 30 );
};

Quadranoid.prototype.render = function ()
{
	switch ( this.status )
	{
		case STATUS_TITLE:
			this.render_title ();
			break;

		case STATUS_GAME:
			this.render_game ();
			break;
	}

};

liwe.events.once ( window, "load", function () { var q = new Quadranoid (); q.init (); } );
